/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.stv.dpds_klient;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.nio.channels.DatagramChannel;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Martin Strouhal
 */
public class Receiver extends Thread{
    
    private DatagramSocket socket;
    private Networker networker;
    
    public Receiver(Networker n){
        try {
            socket = new DatagramSocket();
        } catch (SocketException ex) {
            Logger.getLogger(Receiver.class.getName()).log(Level.SEVERE, null, ex);
        }
        networker = n;
        this.start();
    }

    @Override
    public void run() {
        while(true){
            DatagramPacket prijatyPaket = null;
            try {
                socket.receive(prijatyPaket);
            } catch (IOException ex) {
                Logger.getLogger(Receiver.class.getName()).log(Level.SEVERE, null, ex);
            }
            networker.zpracujPaket(prijatyPaket);
        }
    }
}
